#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.
#
# Modified to make a template file for a multi-binary package with separated
# build-arch and build-indep targets  by Bill Allombert 2001

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# This has to be exported to make some magic below work.
export DH_OPTIONS

CFLAGS = -Wall -g

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	INSTALL_PROGRAM += -s
endif

configure: configure-stamp
configure-stamp:
	dh_testdir
	./configure --prefix=$(CURDIR)/debian/tmp/usr --enable-generic --disable-pdf  --with-mpi=mpich
	touch configure-stamp


#Architecture 
build-arch: configure build-arch-stamp
build-arch-stamp:
	$(MAKE)
	touch build-arch-stamp

build-indep: configure build-indep-stamp
build-indep-stamp:
	$(MAKE) documentation
	touch build-indep-stamp

build: build-arch build-indep

clean:
	dh_testdir
	dh_testroot
	-rm -f build-arch-stamp build-indep-stamp configure-stamp
	-$(MAKE) clean
	-$(MAKE) distclean
	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs
	$(MAKE) install
	mv $(CURDIR)/debian/tmp/usr/bin/FreeFem++ \
		$(CURDIR)/debian/tmp/usr/bin/FreeFem++-x11
	dh_install

# This single target is used to build all the packages, all at once, or
# one at a time. So keep in mind: any options passed to commands here will
# affect _all_ packages. Anything you want to only affect one package
# should be put in another target, such as the install target.
binary-common:
	dh_testdir
	dh_testroot
	dh_installman
	dh_link
	dh_strip
	dh_compress 
	dh_fixperms
#	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture independant packages using the common target.
binary-indep: build install
	dh_installchangelogs -k HISTORY
	dh_installdocs
	dh_installexamples
	$(MAKE) -f debian/rules DH_OPTIONS=-i binary-common

# Build architecture dependant packages using the common target.
binary-arch: build install
	$(MAKE) -f debian/rules DH_OPTIONS=-a binary-common

binary-%: build install
	$(MAKE) -f debian/rules binary-common DH_OPTIONS=-p$*

binary: binary-arch binary-indep
.PHONY: build clean binary-indep binary-arch binary install configure
